package com.synnex.mobile.servier.core.calendar.dao.impl;

import com.synnex.mobile.generic.dao.impl.GenericHibernateDaoImpl;
import com.synnex.mobile.servier.core.calendar.dao.CalendarDao;
import com.synnex.mobile.servier.core.calendar.dto.Calendar;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: kerryf
 * Date: 13-8-6
 * To change this template use File | Settings | File Templates.
 */
public class CalendarDaoImpl extends GenericHibernateDaoImpl<Calendar,Integer> implements CalendarDao {

    public List<Calendar> listCalendar(Date date) {
        Criteria c = this.getSession().createCriteria(Calendar.class);
        if(date!=null){
            c.add( Restrictions.eq("day",date));
        }
        return c.list();
    }

    public void addCalendar(Calendar calendar) {
        super.save(calendar);
    }

    public void deleteCalendar(Integer id) {
        super.delete(super.get(id));
    }

    public Calendar getCalendarById(Integer id) {
        return super.get(id);
    }

    public void editCalendar(Calendar calendar) {
        super.update(calendar);
    }
}
